﻿using System;
using System.Reflection;
using System.Windows;
using System.Windows.Media;
using System.IO;

namespace Avivo.Tools.Sprite
{
	public partial class Settings
	{
		#region Application
		public static string ApplicationName
		{
			get
			{
				return string.Format("{0} v{1}", ProductName, ProductVersion);
			}
		}

		public static string ProductName
		{
			get
			{
				string result = null;
				Assembly assembly = Assembly.GetExecutingAssembly();
				object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
				if (attributes != null && attributes.Length > 0)
				{
					result = (attributes[0] as AssemblyTitleAttribute).Title;
				}
				return result;
			}
		}

		public static string ProductVersion
		{
			get
			{
				Assembly assembly = Assembly.GetExecutingAssembly();
				Version version = assembly.GetName().Version;
				string result = string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.Build);
				return result;
			}
		}
		#endregion

		#region Registry
		static Settings()
		{
			Config.DefaultCache = false;
			Config.DefaultSource = ConfigSource.Registry;
			Config.RegistryRootPath = @"Software\Avivo\xbsprite\";
		}

		public static bool EnableCss
		{
			get
			{
				bool result;
				return Config.Get("EnableCss", out result) ? result : true;
			}
			set
			{
				Config.Set("EnableCss", value);
			}
		}

		public static bool BuildSampleHtml
		{
			get
			{
				bool result;
				return Config.Get("BuildSampleHtml", out result) ? result : true;
			}
			set
			{
				Config.Set("BuildSampleHtml", value);
			}
		}

		public static string BaseClassName
		{
			get
			{
				string result;
				return Config.Get("BaseClassName", out result) && !string.IsNullOrEmpty(result) ? result : "button";
			}
			set
			{
				Config.Set("BaseClassName", value);
			}
		}

		public static string InputDirectory
		{
			get
			{
				string result;
				return Config.Get("InputDirectory", out result) && !string.IsNullOrEmpty(result) ? result : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Sprites");
			}
			set
			{
				Config.Set("InputDirectory", value);
			}
		}

		public static string OutputDirectory
		{
			get
			{
				string result;
				return Config.Get("OutputDirectory", out result) && !string.IsNullOrEmpty(result) ? result : Path.Combine(InputDirectory, "Generated");
			}
			set
			{
				Config.Set("OutputDirectory", value);
			}
		}
		#endregion
	}
}
